/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021.
 * Description: Expose tsc_khz to user space
 * Author: liuwenliang <liuwenliang@huawei.com>
 * Create: 2021-06-07
 */

#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <asm/tsc.h>

static ssize_t tsc_khz_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{
	return sprintf(buf, "%u\n", tsc_khz);
}

static struct kobj_attribute tsc_khz_attr = __ATTR_RO(tsc_khz);
static bool tsc_khz_shown;

static int __init tsc_attr_init(void)
{
	int ret;

	ret = sysfs_create_file(kernel_kobj, &tsc_khz_attr.attr);
	if (ret)
		return ret;
	tsc_khz_shown = true;

	return 0;
}

static void __exit tsc_attr_exit(void)
{
	if (tsc_khz_shown)
		sysfs_remove_file(kernel_kobj, &tsc_khz_attr.attr);
}

module_init(tsc_attr_init);
module_exit(tsc_attr_exit);
